//封装cookie
//document.cookie = "key=value;expires=" + date +";path=/";

function createCookie(key,value,expires,path){
	var cookieStr = encodeURIComponent(key) + "=" + encodeURIComponent(value);
	if(typeof expires == "number"){
		var date = new Date();
		date.setDate(date.getDate() + expires);
		cookieStr += ";expires=" + date;
	}
	if(path){
		cookieStr += ";path=" + path;
	}
	document.cookie = cookieStr;
}

//通过cookie中的key获得value

function getCookieValue(key){
			//先将所有的cookie; 切掉
			var keyValue = document.cookie.split("; ");
			//console.log(keyValue.length);//测试
			for(var i = 0; i < keyValue.length; i++){
				var KEY = keyValue[i].split("=");
				//console.log(KEY);
				if(KEY[0] == encodeURIComponent(key)){
					return decodeURIComponent(KEY[1]);
				}
			}	
	}

//移出cookie.
function removeCookie(key,path){
			if(path){
				document.cookie = encodeURIComponent(key) + "=;expires=" + new Date(0) + ";path=" + path;
			}else{
				document.cookie = encodeURIComponent(key) + "=;expires=" + new Date(0);
			}
		}


